<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="采集商品ID" prop="collectProductId">
        <el-input size="small" v-model="queryParams.collectProductId" placeholder="请输入采集商品ID"/>
      </el-form-item>
      <el-form-item label="商品编码" prop="skuCode">
        <el-input size="small" v-model="queryParams.skuCode" placeholder="请输入商品编码"/>
      </el-form-item>
      <el-form-item label="排序类型：" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择排序类型" filterable>
          <el-option v-for="(item,index) in dict.type.product_sales_statistics_time" :key="index"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="storeUserRelateList" @selection-change="handleSelectionChange" border stripe>
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="采集商品ID" prop="collectProductId" align="center"/>
      <el-table-column label="商品SKU" prop="skuCode" align="center"/>
      <el-table-column label="商品图片" prop="skuImage" align="center" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.skuImage" :width="60"></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="采购链接" prop="skuBuyLink" align="center" width="350">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.skuBuyLink" placement="top">
            <el-link type="primary" :href="scope.row.skuBuyLink">{{ scope.row.skuBuyLink.slice(0, 40) + '····' }}</el-link>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="商品价格" prop="skuPrice" align="center" width="100"/>
      <el-table-column label="商品属性" prop="skuProperty" align="center"/>
      <el-table-column label="7天销售量" prop="sevenDaysCount" align="center" width="100"/>
      <el-table-column label="15天销售量" prop="fifteenDaysCount" align="center" width="100"/>
      <el-table-column label="30天销售量" prop="thirtyDaysCount" align="center" width="100"/>
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
  </div>
</template>

<script>
import {
  delProductUserRelate
} from "@/api/commission/commission";
import logisticsVoucher from "@/views/order/supplementOrder/logisticsVoucher.vue";
import purchaseVoucher from "@/views/order/supplementOrder/purchaseVoucher.vue";
import {collectProductSalesStatistics, getLogisticsProof} from "@/api/order/supplementOrder";
import {getPurchaseProofList} from "@/api/commission/orderCommission"
import {getStoreInfo} from "@/api/order/orderApi";

export default {
  name: "StoreUserRelate",
  components: {logisticsVoucher, purchaseVoucher},
  dicts: ['product_sales_statistics_time'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户店铺维护关联表格数据
      storeUserRelateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: '0',
        collectProductId: undefined,
        skuCode: undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户店铺维护关联列表 */
    getList() {
      this.loading = true;
      collectProductSalesStatistics(this.queryParams).then(response => {
        this.storeUserRelateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.queryParams)
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户商品提成配置";
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.userId || this.ids;
      this.$modal.confirm('是否确认删除该用户数据？').then(() => {
        this.loading = true;
        return delProductUserRelate(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('seller/storeUserRelate/export', {
        ...this.queryParams
      }, `storeUserRelate_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-table__header-wrapper th.redText {
  color: #ff0000;
}
</style>
